package com.secondmybatis.Exception;

import com.secondmybatis.entity.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

// 全局异常处理器 ->可以免去繁杂的try catch
// @RestControllerAdvice = @ControllerAdvice+@ResponseBody
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler   // 指定处理何种异常
    public Result doException(Exception ex){
        System.out.println(ex.getMessage());
        return Result.error("出错了，请联系管理员");
    }
}
